package change.service;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import change.service.dao.ChangeDAO;
import change.service.entity.Change;

@Component
@Path("/change")
public class ChangeBU {

	@Autowired
	ListChanges listChanges;

	@Autowired
	private ChangeDAO changeDao;
	
	public ChangeBU() {
		// TODO Auto-generated constructor stub
	}

	@GET
	@Path("/firstcountry")
	@Produces("text/plain")
	public String ping() {
		return "CANADA";
	}


	@GET
	@Path("/allcountries")
	@Produces("application/json")
	public List<String> getAllCountries() {
		List<String> country = new ArrayList<String>();
		for (Change c : listChanges.getChangeList()) {
			country.add(c.getCountry());
		}
		return country;
	}

	@GET
	@Path("/allchanges")
	@Produces("application/json")
	public ListChanges getAllChanges() {
		listChanges.setChangeList(changeDao.getAllChange());
		return (ListChanges) listChanges;
	}

	@GET
	@Path("/getchange/{input}")
	@Produces("application/json")
	public Change getChangeRate(@PathParam("input") String input) {
		Change currentChange = null;
		for (Change c : listChanges.getChangeList()) {
			if(c.getCountry().equalsIgnoreCase(input))
				currentChange = c;
		}
		return currentChange;
	}

}
